package com.cusi.service;

import com.alibaba.fastjson.JSONObject;
import com.cusi.mapper.UserMapper;
import com.cusi.pojo.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Boolean authLogin(JSONObject jsonObject) {
        UsernamePasswordToken token = new UsernamePasswordToken
                (jsonObject.getString("username"),jsonObject.getString("password"));
        Subject subject = SecurityUtils.getSubject();
        subject.login(token);
        return true;
    }

    @Override
    public User queryInfo(String username, String password) {
        return userMapper.queryInfo(username,password);
    }
}
